import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/viewmodel/elder_filter_setting_view_model.dart';
import 'package:ls_work/widgets/common_widget.dart';
import 'package:saas_order_meal/res/resources.dart';
class ElderFilterSettingPage extends BaseStatefulMvvmWidget{
  @override
  State<StatefulWidget> createState() => _ElderFilterSettingState();

}

class _ElderFilterSettingState extends BaseMvvmState<ElderFilterSettingViewModel,ElderFilterSettingPage>{
  @override
  Widget? buildLoadingContentView() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        TitleValueWidget(title: '选择长者', value: viewModel.filterOld.isEmpty?"":"已选${viewModel.filterOld.length}人",padding: EdgeInsets.symmetric(horizontal: 16,vertical: 15),arrow: Icon(Icons.keyboard_arrow_right_rounded)).onTap((){
          viewModel.toChooseElder();
        }),
        Gaps.dividerLine,
        SizedBox(height: 15,),
        CommonText('选择使用的功能',textSize: 15).addToContainer(padding: EdgeInsets.symmetric(horizontal: 16)),
        SizedBox(height: 14,),
        ...[
          functionCheck('长者列表',viewModel.elderList).onTap((){
            setState(() {
              viewModel.elderList = !viewModel.elderList;
            });
          }),
          functionCheck('照护实施',viewModel.nurseUse).onTap((){
            setState(() {
              viewModel.nurseUse = !viewModel.nurseUse;
            });
          }),
          functionCheck('点餐',viewModel.mealUse).onTap((){
            setState(() {
              viewModel.mealUse = !viewModel.mealUse;
            });
          }),
        ].insertWidget( Gaps.dividerLine),
        
        SizedBox().setWeight(1),
        TextButton(onPressed: (){
          viewModel.saveFilterSetting();
        }, child: CommonText('保存',textColor: Colors.blue),
        style: ButtonStyle(
          shape: WidgetStateProperty.all(StadiumBorder(side: BorderSide(color: Colors.blue))),
          minimumSize: WidgetStateProperty.all(Size(double.infinity, 44))
        ),).addToContainer(margin: EdgeInsets.symmetric(horizontal: 16,vertical: 15))
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(title: Text("长者默认筛选设置"),),
      body: loadingContentWidget,
    );
  }

  Widget functionCheck(String title,bool checked){
    return Row(
      children: [
        Icon(checked?Icons.radio_button_checked: Icons.radio_button_off,color: checked?Colours.app_main:Colors.grey,),
        SizedBox(width: 10,),
        CommonText(title,textSize: 15)
      ],
    ).addToContainer(padding: EdgeInsets.symmetric(horizontal: 16,vertical: 10));
  }

  @override
  ElderFilterSettingViewModel createViewModel() {
    return ElderFilterSettingViewModel(context);
  }

  @override
  void onRetryClick() {
    // TODO: implement onRetryClick
  }

}